import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
class TreeNode {
    char val;
    TreeNode left;
    TreeNode right;
    public TreeNode() {}
    public TreeNode(char val) {
        this.val = val;
    }


}
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
            String inp = in.nextLine();
            //TreeNode root = new TreeNode(inp.charAt(0));
            TreeNode root = new TreeNode();
            creat(inp, root, 0, inp.length());
            mid(root);

    }

    public static void creat(String inp, TreeNode root, int i, int len) {
        if (i > len) {
            return;
        }
        root.val = inp.charAt(i);


        if (root.left == null) {
            i++;
            root.left = new TreeNode(inp.charAt(i));
        }
        if (root.right == null) {
            i++;
            root.right = new TreeNode(inp.charAt(i));
        }
        if (root.val == '#') {
            return;
        }
        creat(inp, root.left, i + 1, len);
        creat(inp, root.right, i + 1, len);

    }

    public static void mid(TreeNode root) {
        if(root.val == '#'){
            return;
        }
        if (root.left == null && root.right == null) {
            System.out.print(root.val + ' ');
            return;
        }
        // if (root.left != null && root.right == null) {
        //     mid(root.left);

        // }

        // if (root.left == null && root.right != null) {
        //     System.out.print(root.val + ' ');
        //     mid(root.right);
        // }
        mid(root.left);
        System.out.print(root.val + ' ');
        mid(root.right);
        return;





    }

}




